package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.resutl.PageResult;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description NursingProjectController
 * @Author shuaijie LI
 * @Date 2024-08-24
 */
@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    private ResponseResult<PageResponse<NursingProjectVo>> page(
            @ApiParam(value = "护理项目名称")
            @RequestParam(value = "name",required = false) String name,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示条数")
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
            @ApiParam(value = "状态（0：禁用，1：启用）")
            @RequestParam(value = "status",required = false) Integer status
    ){

        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.page(name,pageNum,pageSize,status);
        return ResponseResult.success(nursingProjectPageInfo);
    }

    @ApiOperation(value = "新增" ,notes = "新增")
    @PostMapping
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.addNursingProject(nursingProjectDto);
        return ResponseResult.success();
    }

    @ApiOperation(value = "根据id查询" ,notes = "根据id查询")
    @GetMapping("/{id}")
    public ResponseResult getById(
            @ApiParam(value = "护理项目id",required = true)
            @PathVariable("id") Long id){
        NursingProject nursingProject = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProject);
    }

    @ApiOperation(value = "修改" ,notes = "修改")
    @PutMapping
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return ResponseResult.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @ApiOperation(value = "删除" ,notes = "删除")
    @DeleteMapping("/{id}")
    public ResponseResult delete(
            @ApiParam(value = "护理项目id",required = true)
            @PathVariable("id") Long id){
        nursingProjectService.delete(id);
        return ResponseResult.success();
    }
    /**
     * 修改状态
     * @param id
     * @param status
     * @return
     */
    @ApiOperation(value = "修改状态" ,notes = "修改状态")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(
            @ApiParam(value = "护理项目id",required = true)
            @PathVariable("id") Long id,
            @ApiParam(value = "状态",required = true)
            @PathVariable("status") Integer status){
        nursingProjectService.updateStatus(id,status);
        return ResponseResult.success();
    }
}
